package com.example.mvc.mapper;

import com.example.mvc.bean.Book;
import com.example.mvc.bean.History;
import com.example.mvc.bean.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

//借（还）阅的mapper
public interface BookBorrowMapper {
    //处于借出状态的图书列表
    //status 1: 处于借出状态   0:处于还回的状态（即在库）
    @Select("SELECT * FROM history WHERE status=1")
    List<History> getBorrowList();

    //还书，即把借出历史表的status改为0 ,归还日期改为当前日期
    @Update("UPDATE history SET status=0 ,endtime=#{returnDate} WHERE hid=#{returnBookId}")
    int bookReturn(@Param("returnBookId") int returnBookId,@Param("returnDate") String returnDate);



    //已经归还的列表
    @Select("SELECT * FROM history WHERE status=0")
    List<History> bookAlreadyReturnedList();


    //借出和归还的列表
    @Select("SELECT * FROM history")
    List<History> bookHistoryList();

    //在BookBorrowMapper.xml实现
    List<History> getQueryBookBorrowHistoryListByName(String queryBookName);

    //同一种借（还）历史列表的
    @Select("SELECT * FROM history WHERE bid=#{bookId}")
    List<History> borrowRecordListServlet(int bookId);


    //用户借书
    @Insert("INSERT INTO history (aid,bid,card,bookname,adminname,username,begintime,endtime,status)VALUE(#{aid},#{bid},#{card},#{bookname},#{adminname},#{username},#{begintime},#{endtime},#{status})")
    int   userBorrowBook(History history);

    //用戶借阅信息

    @Select("SELECT * FROM history WHERE aid=#{aid} AND status=1")
    List<History> getBorrowBookListByUser(User user);

    //用户借阅历史（已经还了）
    @Select("SELECT * FROM history WHERE aid=#{aid} AND status=0")
    List<History> borrowBookHistoryListByUser(User user);
}
